Skip to content

fix(wsl): a bridge pane keeps its folder when its distro stops while Orca is quit - #35141

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-bridge-restore-cwd
Oct 28, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-bridge-restore-cwd

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A terminal that runs a WSL distro from the Windows app (a "bridge" pane) forgets which folder you had cd'd into if the distro is stopped while Orca is closed. When you reopen Orca, the pane comes back at the project's top folder. Orca now writes down the folder when you quit, so the pane reopens where you left it.

What Changed

Before: say you open a bridge pane in \\wsl.localhost\Ubuntu\home\me\repo, run cd deep, quit Orca, and the distro then stops (wsl --terminate, a reboot, WSL idling it). The pane's history comes back, but it opens in repo, not repo/deep.

After: the same pane reopens in repo/deep.

Mechanism:

  • Why the folder was lost: most shells report their folder to Orca at every prompt (OSC 7). Bash started directly through wsl.exe does not, so Orca only ever knew the folder the pane started in. Sleep already fixes this by asking the distro for the shell's folder (/proc/<pid>/cwd) before its last save.
  • What quit does now: when the app quits, the terminal service stays running and only takes a final save of each pane. Before that save, Orca now reads the folders of the live bridge panes once, with the same probe Sleep uses, and the save records them.
    • The read only runs if the distro is confirmed running. It never starts a stopped distro.
    • It runs once per distro, shared by all that distro's panes.
    • It is limited to 1 second overall, so a slow distro can't hold up quitting (the quit deadline is 20 s, and the other quit steps run alongside).
    • If the read fails or times out, the save keeps the start folder, as before.
  • Code changes:
    • The per-pane folder map Sleep used is renamed probedShellCwds. It is now honoured by any final save that sets it (Sleep or quit). Only those exclusive final passes set it.
    • readDaemonWslSleepCwd gains an optional time cap.
    • A new readDaemonWslQuitCwds reads all bridge panes in parallel.

Why

This is complementary to the regression fix in the mover's pause path, not a replacement for it. Device evidence shows that path used to record the bridge pane's folder and no longer does; that fix is tracked separately. This PR covers a case that path never covered: plain quit, after which the distro stops. Before this, nothing recorded the folder in that case, whether or not a move happened.

Alternatives considered:

  • Make bridge bash report its folder. Rejected: it would change how the user's own distro shell starts, and moved projects (served from inside the distro) already get folder reports.
  • Re-read the folder at every periodic save. Deferred: it starts one wsl.exe per save, which costs performance and is the kind of repeated process start that security software flags.

Reading once at quit covers "quit, then the distro stops" with one bounded read.

Not covered: if the distro is stopped while Orca is still open, the pane is already gone by the time you quit, so there is no shell left to ask. It keeps its start folder, as before.

Flag-off: this does not depend on ORCA_INTERNAL_WSL_HOSTS. Off Windows, and on Windows with no WSL bridge panes, quit does no reads and saves exactly as before.

User-risk: low. On Windows with live WSL bridge panes, quit may take up to 1 s longer, only while waiting on a running distro. A failed read keeps today's behaviour.

Linked Issue

Found in on-device WSL verification (5e: terminate + quit + relaunch, and terminate-while-quit).

Visual Proof

N/A. This changes which folder a restored terminal starts in. Covered by adapter tests that drive quit, a distro stop, and the relaunch restore.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New src/main/daemon/daemon-pty-adapter-wsl-quit-cwd.test.ts uses the real daemon adapter, a mocked distro process read and a simulated win32 platform. On main, 3 of its 5 tests fail.

  • Quit's final save records the shell's folder, read with the running-distro guard.
  • Quit, then the distro stops, then relaunch: the pane cold-restores in that folder.
  • An unreadable distro keeps the start folder.
  • A distro that never answers: quit finishes on its budget and keeps the start folder.
  • A non-WSL pane: no distro read.

daemon-wsl-sleep-cwd.test.ts also covers the parallel quit read and its budget.

Checks run: pnpm tc, pnpm run typecheck:ci, 11 daemon test files (123 tests passing, including the existing Sleep-folder, distro-loss, relaunch, history-recovery and cold-restore suites), pnpm run check:code-quality:changed, anti-slop oxlint, ast-grep scan and gates.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • SSH: remote panes have no WSL distro, so nothing changes.
  • Folder workspaces: nothing here depends on git.
  • Wire compatibility: nothing new crosses the client/daemon protocol; the read runs on the client side through the existing probe.
  • Older daemons without incremental checkpoints save through their old path, which never carried a probed folder.

Status

Ready for review.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@nwparker

Copy link
Copy Markdown
Contributor Author

STATUS: ready. Head 94fc77a, branched from origin/main aab2254. At quit, live WSL bridge panes get their shell folder read once (same probe as Sleep, never boots a stopped distro, 1 s overall cap) and quit's final save records it. This closes a gap that has always existed, not a regression: the 9ac..f59 comparison shows no change in this area. Checks: pnpm tc, typecheck:ci, 11 daemon test files (123 tests passing; the new suite fails 3 of 5 on main), code-quality, anti-slop, ast-grep scan and gates. Open: a distro stopped while Orca is still open (pane already gone at quit) isn't covered. That needs the deferred periodic re-read.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f1af35be-664a-4f2a-b30b-4d2ecd758fcd
Commits

Reviewing files that changed from the base of the PR and between a6fdeda and 94fc77a.

Files selected for processing: 7
  • src/main/daemon/daemon-pty-adapter-wsl-quit-cwd.test.ts
  • src/main/daemon/daemon-pty-checkpoint-persistence.ts
  • src/main/daemon/daemon-pty-event-subscriptions.ts
  • src/main/daemon/daemon-pty-runtime-state.ts
  • src/main/daemon/daemon-pty-session-control.ts
  • src/main/daemon/daemon-wsl-sleep-cwd.test.ts
  • src/main/daemon/daemon-wsl-sleep-cwd.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker merged commit 77048d5 into main Oct 28, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant